<?php

class Rapide_Log
{
	private
		$_aAdapters = array(),
		$_sDefaultAdapter;

	public function setDefaultAdapter($sAdapter)
	{
		if(!isset($this->_aAdapters[$sAdapter]))
		{
			$sError = sprintf('Adapter %s has not been registered');
			throw new Rapide_Log_Exception($sError);
		}

		$this->_sDefaultAdapter = $sAdapter;
	}

	public function registerAdapter(Rapide_Log_Adapter_Interface $oAdapter, $sAdapter)
	{
		if(isset($this->_aAdapters[$sAdapter]))
		{
			$sError = sprintf('Adapter %s exists', $sAdapter);
			throw new Rapide_Log_Exception($sError);
		}

		$this->_aAdapters[$sAdapter] = $oAdapter;

		if(count($this->_aAdapters) == 1)
			$this->setDefaultAdapter($sAdapter);
	}

	public function log($sMessage, $sAdapter = null)
	{
		if(!isset($sAdapter))
		{
			if(!isset($this->_sDefaultAdapter))
			{
				$sError = 'Default adapter has not been set';
				throw new Rapide_Log_Exception($sError);
			}

			$sAdapter = $this->_sDefaultAdapter;
		}

		if(!isset($this->_aAdapters[$sAdapter]))
		{
				$sError = 'Adapter %s does not exist';
				throw new Rapide_Log_Exception($sError);
		}

		$this->_aAdapters[$sAdapter]->log($sMessage);
	}
}

?>